package com.cooba.activitys.Living;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cooba.R;
import com.cooba.bean.LivingDetailBean;

import java.io.Serializable;
import java.util.List;

public class LivingContentAddTextActivity extends AppCompatActivity implements View.OnClickListener {

    private EditText add_content_new_text_type_text_et;
    private TextView add_content_new_type_text_type_add_again_tv;
    private TextView add_content_new_type_text_type_finish_tv;
    private List<LivingDetailBean.LivingDetailContent> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_living_add_content_text_type_add);
        list= (List<LivingDetailBean.LivingDetailContent>) getIntent().getSerializableExtra("living_info_list");
        Toast.makeText(this, "数组大小:"+list.size(), Toast.LENGTH_SHORT).show();
        initView();
        initListener();
    }

    private void initListener() {
        add_content_new_type_text_type_add_again_tv.setOnClickListener(this);
        add_content_new_type_text_type_finish_tv.setOnClickListener(this);
    }

    private void initView() {
        add_content_new_type_text_type_add_again_tv= (TextView) findViewById(R.id.add_content_new_type_text_type_add_again_tv);
        add_content_new_type_text_type_finish_tv= (TextView) findViewById(R.id.add_content_new_type_text_type_finish_tv);
        add_content_new_text_type_text_et= (EditText) findViewById(R.id.add_content_new_text_type_text_et);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.add_content_new_type_text_type_add_again_tv:
                if (!TextUtils.isEmpty(add_content_new_text_type_text_et.getText().toString().trim())){
                    if (list.size()>10){
                        Toast.makeText(this,"最多只能添加10条数据!",Toast.LENGTH_SHORT).show();
                        return;
                    }
                    addList();
                    Intent intent =new Intent(this,LivingContentTypeActivity.class);
                    intent.putExtra("living_info_list", (Serializable) list);
                    startActivity(intent);
                }else {
                    Toast.makeText(this,"内容不能为空!",Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.add_content_new_type_text_type_finish_tv:
                finish();
                break;
            default:break;
        }
    }

    private void addList() {
        LivingDetailBean.LivingDetailContent content=new LivingDetailBean.LivingDetailContent();
        content.setLiveId(list.get(0).getLiveId());
        content.setMessageType("0");
        content.setIsTitle("0");
        content.setMessage(add_content_new_text_type_text_et.getText().toString().trim());
        list.add(content);
    }
}
